#include<unistd.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<sys/types.h>

int main(int argc,char **argv)
{
    pid_t pid;
    int fd[2];
    int res = pipe(fd);
    if(res != 0)
    {
        perror("pipe error\n");
        exit(1);
    }
    pid=fork();
    if(pid<0)
    {
        perror("fork error\n");
        exit(1);
    }
    if(pid == 0)
    {
        char buff[1024]={0};
      
        close(fd[1]);
        dup2(fd[0],STDIN_FILENO);
        close(fd[0]);
        //setvbuf(stdin, NULL, _IOLBF, 0);
        while (1)
        {
            scanf("%s",buff);
            //read(fd[0],buff,sizeof(buff));
            printf("recv %s\n",buff);
        }
        
    }
    else if(pid > 0 )
    {
        char buff[1024];
        close(fd[0]);
        while (1)
        {
          
           // scanf("%s",buff);
           // printf("send:%s\n",buff);
            write(fd[1],"hello\n",6);
        }
        
    }
    return 0;
}